package com.ukao.cashregister.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.cashregister.R;
import com.ukao.cashregister.bean.AddressList;
import com.ukao.cashregister.listener.OnItemChildClickListener;
import com.ukao.cashregister.utils.CheckUtils;

import java.util.List;

/**
 * Created by ukaodev on 2017/6/14.
 */

public class OftenPlaceAdapter extends CommonAdapter<AddressList> {




    public OftenPlaceAdapter(Context context, List<AddressList> datas) {
        super(context, datas, R.layout.adapter_often_place);
    }


    private OnItemChildClickListener mOnItemChildClickListener;
    public  void  setOnItemChildClickListener(OnItemChildClickListener mOnItemChildClickListener){
        this.mOnItemChildClickListener=mOnItemChildClickListener;
    }


    @Override
    public void convert( final  ViewHolder viewHolder, AddressList item) {


        TextView defTxt =  viewHolder.getView(R.id.def_txt);
        TextView phone =  viewHolder.getView(R.id.phone);
        TextView name =  viewHolder.getView(R.id.name);
        TextView regionalDesc =  viewHolder.getView(R.id.regionalDesc);
        TextView detail =  viewHolder.getView(R.id.detail);
        ImageButton editBtn =  viewHolder.getView(R.id.edit_btn);
        ImageButton deleteBtn =  viewHolder.getView(R.id.delete_btn);
        ImageView checkIamge = viewHolder.getView(R.id.check_iamge);
        phone.setText(item.getPhone());
        regionalDesc.setText(item.getRegionalDesc());
        detail.setText(item.getDetail());
        name.setText(item.getName());
        if (item.getDef()==1) {
            checkIamge.setImageResource(R.drawable.check_box_check);
            defTxt.setText("默认地址");
            defTxt.setTextColor(mContext.getResources().getColor(R.color.oftenplace_back));
        } else {
            defTxt.setText("设为默认");
            checkIamge.setImageResource(R.drawable.check_box_normal);
            defTxt.setTextColor(mContext.getResources().getColor(R.color.oftenplace));

        }
        View.OnClickListener  OnClickListener= new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!CheckUtils.isNull(mOnItemChildClickListener))
                    mOnItemChildClickListener.onChildItemClick(v.getId(), getPosition(viewHolder));


            }

        };
        deleteBtn.setOnClickListener(OnClickListener);
        editBtn.setOnClickListener(OnClickListener);
    }





}
